package com.zhongketech.sunflower.view;

import com.zhongketech.sunflower.database.ApplicationData;
import com.zhongketech.sunflower.database.Data;
import com.zhongketech.sunflower.database.PhoneNumberData;
import com.zhongketech.sunflower.util.Constants;
import com.zhongketech.sunflower.util.Utilities;

import android.content.Context;
import android.widget.ArrayAdapter;


public class PhoneNumList {


	private static PhoneNumList instance = null;

	private Context context = null;
	private ArrayAdapter<String> arrayAdapter = null;

	private int MAX_LOG_COUNT = 100;
	//private List<String> logString = new ArrayList<String>();


	private PhoneNumList()
	{

	}

	public static PhoneNumList getInstance(Context c)
	{   
		if(null == instance || c != instance.context)
		{
			instance = new PhoneNumList();
			instance.context = c;
			instance.init();

		}

		return instance;   
	}

	private void init()
	{
		arrayAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1);
		update();
	}

	public ArrayAdapter<String> getAdapter()
	{
		return arrayAdapter;
	}

	public void update()
	{
		arrayAdapter.clear();

		//Utilities.logCat("UninstallList", "UninstallList update:"+Data.getinstance().getPhoneNumberCount(), Constants.LOG_INFO);


		for(int i = 0;i < Data.getinstance().getDataCount(Data.DATATYPE_PHONEBLACKLIST);i ++)
		{
			PhoneNumberData num = (PhoneNumberData)Data.getinstance().getData(i,Data.DATATYPE_PHONEBLACKLIST);
			String show = "";
			if(null != num.getName())
			{
				show = num.getName();
			}

			if(null != num.getNumber())
			{
				if("".equals(show))
				{
					show = num.getNumber();
				}
				else
				{
					show = show + ":" +num.getNumber();
				}

			}

			arrayAdapter.add(show);
		}
	}
}
